package task.snake.controller;

import java.awt.Dimension;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import task.snake.view.swingimpl.PlayPanel;

/**
 * Class extends class ComponentAdapter and handle events witch occur when the
 * component's size changes and when the component has been made visible.
 * 
 * @author Nadezhda Makarkina
 * 
 */
public class ComponentListenerImpl extends ComponentAdapter {

	private Dimension lastSize = null;
	private PlayPanel playPanel;

	/**
	 * Initializes a newly created ComponentListenerImpl.
	 * @param playPanel
	 */
	public ComponentListenerImpl(PlayPanel playPanel) {
		this.playPanel = playPanel;
	}

	@Override
	public void componentShown(ComponentEvent e) {
		if (!playPanel.getSize().equals(lastSize)) {
			playPanel.rebuildBuffer();
			lastSize = playPanel.getSize();
		}
	}

	@Override
	public void componentResized(ComponentEvent e) {
		if (!playPanel.getSize().equals(lastSize)) {
			playPanel.rebuildBuffer();
			lastSize = playPanel.getSize();
		}
	}
}
